package com.my.content.liveproject;

import android.support.v4.app.Fragment;
import android.util.SparseArray;

import com.my.content.attention.AttentionFragment;
import com.my.content.hot.HotFragment;
import com.my.content.near.NearFragment;
import com.my.content.talent.TalentFragment;

/**
 * Created by 李雪斌 on 2016/12/16.
 **/
public class FragmentFactory {

    private static final int ATTENTION = 0;
    private static final int HOT = 1;
    private static final int NEAR = 2;
    private static final int TALENT = 3;
    public static SparseArray<Fragment> fragments = new SparseArray<>();

    public static Fragment createFragment(int index) {
        Fragment fragment = fragments.get(index);
        if (fragment == null) {
            switch (index) {
                case ATTENTION:
                    fragment = new AttentionFragment();
                    break;
                case HOT:
                    fragment = new HotFragment();
                    break;
                case NEAR:
                    fragment = new NearFragment();
                    break;
                case TALENT:
                    fragment = new TalentFragment();
                    break;
            }
            fragments.put(index,fragment);
        }
        return fragment;
    }
}
